<%@ page language="java" contentType="text/html; charset=utf-8"%>
<%@ include file="/taglibs.jsp"%>
<html>
<head>
<title>IT管理后台</title>
<link rel="stylesheet" type="text/css" href="/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="/js/themes/icon.css">
<script type="text/javascript" src="/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/js/easyui_validatebox.js"></script>
<script type="text/javascript" src="/js/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
td {
	font-size: 13px
}
</style>
<script>

</script>
	<script>
		$(function(){
			var products = '${json}';
			var ps=$.parseJSON(products);
			var lastIndex;
			var tag=null;
			$('#tab').datagrid({
				title:'设备分类公有属性信息',
				iconCls:'icon-save',
				nowrap: false,
				striped: true,
				pageSize:20,
				sortName:"id",
				sortOrder:"desc",
				pageList:[10,20,30,40,50],
				url:'/itmanager/sbflgysx/json',
				remoteSort: false,
				idField:'id',
				frozenColumns:[[
				        {field:"ck",checkbox:true}
	                ]],
	                columns:[[
						{title:'公有属性名称',field:"gysxmc",width:120,editor:{
							type:'text',
							options:{
								required:true
								}
							}}
	                ]],
				fit:true,
				border:false,
				pagination:true,
				rownumbers:true,
				showFooter:true,
				toolbar:[{
					text:'添加',
					iconCls:'icon-add',
					handler:function(){
						if(tag==null){
							$('#tab').datagrid('endEdit', lastIndex);
							$('#tab').datagrid('appendRow',{
								gysxmc:''
							});
							lastIndex = $('#tab').datagrid('getRows').length-1;
							$('#tab').datagrid('beginEdit', lastIndex);
							tag='add';
						}
					}
				},'-',{
					text:'保存',
					iconCls:'icon-save',
					handler:function(){
						tag=='add';
						saveall();
					}
				},'-',{
					text:'删除',
					iconCls:'icon-remove',
					handler:function(){
						var rows = $("#tab").datagrid("getSelections");
						var length = rows.length;
						if(length == 0){
							$.messager.alert("友情提示","<br/><b>请先选择记录！</b>","error");
							return false;
						}
						var ids = [];
						for(var i=0;i<length;i++){
							ids.push(rows[i].id);
						}
						ids.join(",");
						$.messager.confirm("友情提示","<br/><b>确定删除记录？</b>",function(result){
								if(result){
									$.ajax({
								 		type:"post",
								 		url:"/itmanager/sbflgysx/delete",
								 		data:"ids="+ids,
								 		success:function(data){
								 			if(data=='success'){
								 		 		var queryParams = $.extend({},$("#tab").datagrid("options").queryParams);
								 				$("#tab").datagrid("reload",queryParams);
								 				$("#tab").datagrid("clearSelections");
								 			}else if(data=='error'){
								 				$.messager.alert("友情提示","<br/><b>删除记录出错！</b>","error");
								 			}
								 		}
								 	});
								}
							});
					}
				},'-',{
					text:'修改',
					iconCls:'icon-edit',
					handler:function(){
						tag='edit';
						saveall();
					}
				},'-',{
					text:'取消',
					iconCls:'icon-undo',
					handler:function(){
						$('#tab').datagrid('rejectChanges');
						tag=null;
					}
				}],
				onBeforeLoad:function(){
					$(this).datagrid('rejectChanges');
				},
				/* onLoadSuccess: function(){
		            function bindRowsEvent(){
		                var panel = $('#tab').datagrid('getPanel');
		                var rows = panel.find('tr[datagrid-row-index]');
		                rows.unbind('click').bind('click',function(e){
		                    return false;
		                });
		                rows.find('div.datagrid-cell-check input[type=checkbox]').unbind().bind('click', function(e){
		                    var index = $(this).parent().parent().parent().attr('datagrid-row-index');
		                    if ($(this).attr('checked')){
		                        $('#tab').datagrid('selectRow', index);
		                    } else {
		                        $('#tab').datagrid('unselectRow', index);
		                    }
		                    e.stopPropagation();
		                });
		            }
		            setTimeout(function(){
		                bindRowsEvent();
		            }, 10);    
		    	}, 
		    	
		    	 
				} */

				onBeforeEdit:function(rowIndex, rowData){
					
				},
				onAfterEdit:function(rowIndex, rowData, changes){
					var rowData1 = $.extend({},rowData,{"sbflid":rowData.sbflmc});
					if(tag=='edit'){
						$.ajax({
							   type: "post",
							   url: "/itmanager/sbflgysx/edit",
							   data: rowData1,
							   success: function(msg){
								   if (msg=='success'){  
						        	  	$.messager.alert('信息提示','修改成功！','right');  
						        	  	$("#tab").datagrid("reload");
						            } else if(msg=='error'){
						            	$.messager.alert('信息提示','修改失败！','error');
						            }
							   }
						});
					}else if(tag=='add'){
						$.ajax({
							   type: "post",
							   url: "/itmanager/sbflgysx/add",
							   data: rowData,
							   success: function(msg){
								   if (msg=='success'){  
						        	  	$.messager.alert('信息提示','添加成功！','right');  
						        	  	$("#tab").datagrid("reload");
						            } else if(msg=='error'){
						            	$.messager.alert('信息提示','添加失败！','error');
						            }
							   }
						});
					}
					tag=null;
				},
				onDblClickRow:function(rowIndex, rowData){
					if (lastIndex != rowIndex){
						if(tag=='add'){
							$('#tab').datagrid('endEdit', lastIndex);
						}else{
							tag='edit';
							$('#tab').datagrid('endEdit', lastIndex);
						}
						$('#tab').datagrid('beginEdit', rowIndex);
					}else{
						$('#tab').datagrid('beginEdit', rowIndex);
					}
					lastIndex = rowIndex;
				},
				onClickRow:function(rowIndex, rowData){
					var row=$('#tab').datagrid('getSelected');
					var index=$('#tab').datagrid('getRowIndex',row);
					if (index == -1){
						$('#tab').datagrid('selectRow',rowIndex);
					}else{
						$('#tab').datagrid('unselectRow',rowIndex);
					}
				}
			});
			
			 $("#tab").datagrid("getPager").pagination({
				   onSelectPage:function(){
					  $("#tab").datagrid("clearSelections");
					  var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
							  {spgysxmc:$("#gysxmc-search").val()}); 
					  $("#tab").datagrid("reload",queryParams);
				   }
			  });
			 
		});
		
		function saveall(){
			 $('#tab').datagrid('acceptChanges'); 
		}

		var find = function(){
			$("#tab").datagrid("clearSelections");
			var queryParams = $.extend({},$("#tab").datagrid("options").queryParams,
					{spgysxmc:$("#gysxmc-search").val()}); 
			$("#tab").datagrid("getPager").pagination({pageNumber:1});
			$("#tab").datagrid("reload",queryParams);
		}
		
		function mtext(target,text){
			$(target).html("&nbsp;");
			$(target).html(text);
		}
		
		function clearSel(oSelect) {
			while (oSelect.childNodes.length > 0) {
				oSelect.removeChild(oSelect.childNodes[0]);
			}
		}
	</script>
</head>
<body class="easyui-layout">
	<div region="north" border="false" style="height:80px;" iconCls="icon-search" title="查询条件">
		<table width="100%" height="100%" style="background-color:#E0ECFF ">
			<thead>
				<tr>
					<!--<td width="10%" align="center">员工姓名：</td>
					<td width="30%"><input type="text" name="spxm" id="xm-search"></td>
					-->
					
					
					<td width="10%" align="center">公有属性名称：</td>
					<td width="30%">
						<input type="text" name="spgysxmc" id="gysxmc-search" />
					</td>
					<td><a class="easyui-linkbutton" iconCls="icon-search" onclick="find()">查询</a></td>
				</tr>
			</thead>
		</table>
	</div>
	<div id="center" region="center">
		<table id="tab"></table>
	</div>
	

</body>
</html>